package traveler.controllers;

import traveler.activities.CourseActivity;
import traveler.activities.GoogleMapsActivity;
import traveler.activities.StepActivity;
import traveler.models.Step;
import traveler.activities.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

public class StepController extends BaseController implements OnClickListener, OnChildClickListener
{
	public final static String TITLE = "title";
	public final static String ANSWER = "answer";
	public final static String QUESTION = "question";
	
	public StepController(Activity activity)
	{
		super(activity);
	}
	
	public void onClick(View v)
	{
		switch(v.getId())
		{
			case R.id.step_btnViewMap :
				Step step = new Step(_activity);
				Intent intent = new Intent(_activity, GoogleMapsActivity.class);
				Bundle bundle = new Bundle();
				
				bundle.putInt(GoogleMapsController.LATITUDE, step.getGeoPoint().getLatitudeE6());
				bundle.putInt(GoogleMapsController.LONGITUDE, step.getGeoPoint().getLongitudeE6());
				
				_activity.startActivity(intent.putExtras(bundle));
				break;
		}
	}
	
	public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
	{
		Step step = new Step(_activity);
		
		Intent intent = new Intent(_activity, CourseActivity.class);
		Bundle bundle = new Bundle();
		
		bundle.putString(StepController.TITLE, "Step " + (childPosition + 1));
		bundle.putString(StepController.ANSWER, step.getAnswer());
		bundle.putString(StepController.QUESTION, step.getQuestion());
		
		intent.putExtras(bundle);
		_activity.startActivity(intent);
		
		return true;
	}
}
